﻿/*
*
* Author: Zero
* Version 1.1
* Se comentó el setType del user por que no me lo están mandando
*
*/

import com.dinmax.flash.central.extension.*
import com.dinmax.flash.central.extension.user.*
import com.dinmax.flash.utilities.xml.XMLUtils

class UserFactory {
	
	public static function getUsers(node:XMLNode):Array {
		var users:Array = new Array();
		for(var usrs:XMLNode = node.firstChild; usrs != null; usrs=usrs.nextSibling){
			if(usrs.nodeType == 1){
				var user:User = UserFactory.getUser(usrs);
				users.push(user);
			};
		};
		return users;
	};
	
	public static function getUser(node:XMLNode):User {
		var usr:User = new User();
		try	{
			usr.setId(Number(XMLUtils.getAttribute(node, "id")));
			usr.setName(XMLUtils.getAttribute(node, "name"));
			usr.setLastName(XMLUtils.getAttribute(node, "lastname"));
			usr.setNick(XMLUtils.getAttribute(node, "nick"));
			//usr.setType(XMLUtils.getAttribute(node, "type"));
			usr.setEmail(XMLUtils.getAttribute(node, "email"));
			usr.setPhone(Number(XMLUtils.getAttribute(node, "phonenumber")));
			usr.setAddresses(AddressFactory.getAddresses(XMLUtils.getNode(node, "addresses")));
			usr.setContacts(ContactFactory.getContacts(XMLUtils.getNode(node, "contacts")));
		} catch (e) {
			trace("ERROR EN USER FACTORY creando el USER"+e);
		}

		return usr;
	};
		
}; // fin de clase